<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
%>
<jsp:include page="../../import.jsp" flush="true" />

<body>


<SCRIPT LANGUAGE="JavaScript">
<!--
$(function(){
	$("#editDiv").dialog({
		autoOpen: false,
		bgiframe: true,
		height: 600,
		width:600,
		modal: true,
		buttons: {
			"提交": function() { 
				//$(this).dialog("close"); 
				_submit();
			}, 
			"取消": function() { 
				$(this).dialog("close"); 
			} 
		}
	});
});
//-->
</SCRIPT>



<!-- <input type="button" id="add" value="增加新业务" onclick="addNewTask();"/> -->
<!-- <s:property value="#session.QDEVELOP_LOGIN_SESSION_KEY.rid"/> -->
<table class="QueryTable">
<thead>
	<th><A HREF="javascript:goOrder('name')">用户名</A></th>
	<th><A HREF="javascript:goOrder('loginname')">登陆名</A></th>
	<th>加密密码</th>
	<th>操作[<A HREF="javascript:addNewUser();">新增用户</A>]</th>
</thead>
<!-- even odd -->
 <s:iterator value="rb.resultList" id="m" status="cust_stat">  
 <TR class='<s:if test="#cust_stat.even">anthor_tr</s:if>'>  
		<TD><s:property value="NAME"/></TD>
		<TD><s:property value="LOGINNAME"/></TD>
		<TD><s:property value="PASSWORD"/></TD>
		<TD>[<A HREF='javascript:editUser(<s:property value="ID"/>,"<s:property value="NAME"/>","<s:property value="LOGINNAME"/>","<s:property value="PASSWORD"/>","<s:property value="INFO"/>","<s:property value="RID"/>")'>修改</A>]
		<!-- <s:if test="#m.SENDNUM==null&&#m.WAITNUM==null&&#m.FINISHNUM==null"> -->
			/ [<A HREF='javascript:delUser(<s:property value="ID"/>,"<s:property value="NAME"/>")'>删除</A>]
		<!-- </s:if> -->
		</TD>
</TR>
 </s:iterator> 
</table>
<jsp:include page="../../pageination.jsp" flush="true" />

<div id="editDiv" title="用户编辑" style="display:none;height:100%">
	<span align='center' >
		<FORM METHOD='POST' ACTION='<%=path%>/security/userEdit.action' onSubmit="return checkData();">
		<TABLE style="height:94%">
		<TR>
			<TD valign='top' >
			<INPUT TYPE="hidden" NAME="id"   id="id" value=''>
			<INPUT TYPE="hidden" NAME="index"   id="index" value=''>
			<INPUT TYPE="hidden" NAME="rid"   id="rid" value=''>
			<INPUT TYPE="hidden" NAME="gid"   id="gid" value=''>
			<TABLE >
			<TR >
					<TD >用户名：</TD>
					<TD><INPUT TYPE="text" NAME="name" id="name"  value=''></TD>
			</TR>
			<TR >
					<TD >登录名：</TD>
					<TD><INPUT TYPE="text" NAME="loginname" id="loginname"  value=''></TD>
			</TR>
				<TR  id="pwdInput" >
					<TD >密码：</TD>
					<TD><INPUT TYPE="password" NAME="password" id="password"  value=''></TD>
				</TR>

					<TR >
					<TD >基本信息：</TD>
					<TD><INPUT TYPE="text" NAME="info" id="info"  value=''></TD>
				</TR>
			</TABLE>
			</TD>
			<TD valign='top'>
			<iframe src='<%=path%>/security/roleInclude.action?forward=list&index=quaryRoles&type=radio' frameborder=0  width="99%"  height="100%"  id="RolesFrame"></iframe>
			</TD>
		</TR>
		</TABLE>			
		</FORM>
	</span>
</div>
<!-- <TEXTAREA id="debug" ROWS="50" COLS="100"></TEXTAREA> -->
</body>
<SCRIPT LANGUAGE="JavaScript">

var _submit = function(){	
	var nameForm  = $('#loginname');
	if(nameForm.val()==''){
		alert("登录名必须输入！");
	}else{
		if($('#id').val()==''){
			var url = "<%=path%>/json/checkUser.action?userName="+nameForm.val()+"&$r"+Math.random();	
			$.getJSON(url, function(json){
				if(json.msg == 'true'){
					dataSend();
				}else{
					alert('登录名'+nameForm.val()+'已存在，请重新输入！');
					nameForm.focus();
					nameForm.val('');
				}
			});
		}else{
			dataSend();
		}
	}
}

var dataSend = function(){
	$('#editDiv').dialog('close');
	wait.show();
	var _rid =window.frames["RolesFrame"].getDtreeRadioValue();
	$('#rid').val(_rid);
	$('form:first').submit();
}

var editUser = function(id,name,loginname,password,info,rid){	
	$('#editDiv').dialog('open');
	$('#pwdInput').attr('style','display:none');
	$('#id').val(id);
	$('#name').val(name);
	$('#loginname').val(loginname);
	$('#password').val(password);
	$('#info').val(info);
	window.frames["RolesFrame"].setDtreeRadioValue(rid);
	$('#index').val('editUser');
	
}

var delUser = function(id,name){
	if(confirm('确定删除任务【'+name+'】?')){
		$('#id').val(id);
		$('#loginname').val('delete');
		$('#index').val('deleteUser');
		_submit();
	}
}
var addNewUser = function(){
	$('#pwdInput').attr('style','display:""');
	$('input').val('');
	window.frames["RolesFrame"].setDtreeRadioValue(null);
	$('#editDiv').dialog('open');
	$('#index').val("addUser");
}

</SCRIPT>
